﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;
using System.Data;

namespace HY.WEB.SA
{
    public partial class _tel_add : PageBase
    {
        public string whe = "", stype = "";
        public string us, um, bh;
        public string tab = "comp_job";
      
        protected void Page_Load(object sender, EventArgs e)
        {
           
            us = Session["ID"].ToString();
            bh = Session["bh"].ToString();
            um = Session["user"].ToString();
            //whe = " cbh in (select cbh from company_fav where sbh='" + bh + "')";

            if (!IsPostBack)
            {
                if (!String.IsNullOrEmpty(Request["stype"]))
                {
                    hidstype.Text = Request["stype"].Trim();                
                }

                if (!String.IsNullOrEmpty(Request["cbh"]))
                {
                    hidcomp.Text = Request["cbh"].Trim();
                } 

                fill();
            }

       
        }
 
     void   fill()
      {           
          //公司分类
         if (stype==""){          
              string tmp=hidcomp.Text.Substring(0,2);
             if (tmp=="CP") stype="company";
              if (tmp=="SO") stype="school";
              if (tmp=="ZJ") stype="zj";
         }

         DataTable s; 
          DataTable e = BLL.Bllbase.get_table(stype);
          ddlcompany.Items.Clear();

          if (stype == "company")
          {
              for (int i = 0; i < e.Rows.Count; i++)
              {
                  ddlcompany.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["cname"].ToString().Trim(), e.Rows[i]["cbh"].ToString().Trim()));
              }

              s = BLL.Bllbase.get_table(stype, "cbh='" + hidcomp.Text + "'");
              if (s.Rows.Count > 0)
              {
                  txtperson.Text = s.Rows[0]["person"].ToString();
                  txttel.Text = s.Rows[0]["ctel"].ToString() + " " + s.Rows[0]["mtel"].ToString();
              }

          }


         //学校
          if (stype == "school")
          {
              for (int i = 0; i < e.Rows.Count; i++)
              {
                  ddlcompany.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["schname"].ToString().Trim(), e.Rows[i]["schbh"].ToString().Trim()));
              }
              s = BLL.Bllbase.get_table(stype, "schbh='" + hidcomp.Text + "'");
              if (s.Rows.Count > 0)
              {
                  txtperson.Text = s.Rows[0]["person"].ToString();
                  txttel.Text = s.Rows[0]["stel"].ToString() + " " + s.Rows[0]["mtel"].ToString();
              }  
          }

         //中介
          if (stype == "zj")
          {
              for (int i = 0; i < e.Rows.Count; i++)
              {
                  ddlcompany.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["zname"].ToString().Trim(), e.Rows[i]["zbh"].ToString().Trim()));
              }
              s = BLL.Bllbase.get_table(stype, "zbh='" + hidcomp.Text + "'");
              if (s.Rows.Count > 0)
              {
                  txtperson.Text = s.Rows[0]["person"].ToString();
                  txttel.Text = s.Rows[0]["tel"].ToString() + " " + s.Rows[0]["mtel"].ToString();
              }
            }

            ddlcompany.DataBind();


          if (hidcomp.Text != "")     //最公司      
              ddlcompany.SelectedIndex = ddlcompany.Items.IndexOf(ddlcompany.Items.FindByValue(hidcomp.Text));

           date1.Text = DateTime.Now.ToString("yyyy-MM-dd");
       
           txtdtime.Text = DateTime.Now.ToLongTimeString().ToString();    
      }

 
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Model.CO.comp_tel TE = new Model.CO.comp_tel();
        

         TE.pbh=bh;
         TE.pname=um;

          TE.cbh = ddlcompany.SelectedValue; //公司编号
          TE.cname = ddlcompany.SelectedText; //公司名称

          TE.person = txtperson.Text; //联系人
          TE.tel = txttel.Text;

          DateTime dtime = DateTime.Now;
          if (!VAN.IsDateTime(date1.Text))
              TE.pdtime = dtime;
          else
              TE.pdtime = DateTime.Parse(date1.Text+" "+txtdtime.Text);

           TE.sdtime = dtime;

           //TE.pmemo= HttpUtility.HtmlEncode(FCKeditor1.Value);
           TE.pmemo = lblmemo.Text;

           BLL.CO.comp_tel CT = new BLL.CO.comp_tel();
           CT.Add(TE);


            Alert.Show("添加完成 ");
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }

       
    }
}